﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Diagnostics;

namespace RemotePrintTimer
{
    static class Program
    {
        private static Mutex mutex = null;
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config"));
            //Process[] processcollection = Process.GetProcessesByName(Application.CompanyName);
            mutex = new Mutex(true, "{E695EA3E-1F3D-44DE-AA3A-BD06E3AF097E}");
            if (!mutex.WaitOne(0, false))
            {
              MessageBox.Show("程序已经在运行！");
            }
            else
            {
                try
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
                }
                finally
                {
                    mutex.ReleaseMutex();
                }
            }
        }

        public static bool AppInstance()
        {
            bool exist = false;
            Process[] MyProcesses = Process.GetProcesses();
            foreach (Process MyProcess in MyProcesses)
            {
                if (MyProcess.ProcessName == Process.GetCurrentProcess().ProcessName)
                {
                    exist = true;
                }
            }
            return exist ;
        }

    }
}
